#include "myqdialog.h"

#include <QDebug>
#include <QMouseEvent>

MyQDialog::MyQDialog(QDialog *parent): QDialog(parent)
{

}


// 鼠标点击事件
void MyQDialog::mousePressEvent(QMouseEvent *e)
{
    //鼠标左键
    if(e->button() == Qt::LeftButton)
    {
        m_ptPress = e->pos();
        qDebug() << pos() << e->pos() << m_ptPress;
        m_bPressed = m_areaMovable.contains(m_ptPress);

    }
}

// 鼠标移动事件
void MyQDialog::mouseMoveEvent(QMouseEvent *e)
{
    if(m_bPressed)
    {
        qDebug() << pos() << e->pos() << m_ptPress;
        move(pos() + e->pos() - m_ptPress);
    }
}

// 鼠标松手事件
void MyQDialog::mouseReleaseEvent(QMouseEvent *)
{
    m_bPressed = false;
}

//设置鼠标按下的区域
void MyQDialog::setAreaMovable(const QRect rt)
{

    if(m_areaMovable != rt)
    {
        m_areaMovable = rt;
    }
}
